package com.ptmall.app.ui.activity;

import android.os.Bundle;
import android.widget.GridView;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.bean.ProductBean;
import com.ptmall.app.bean.model.HomePageIndex;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.ui.adapter.GoodListAdapter;
import com.ptmall.app.ui.adapter.HomePageReCommendAdapter;
import com.ptmall.app.ui.adapter.LikeGoodAdapter;
import com.ptmall.app.view.TitleBarView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/1/24.
 */

public class RqActivity extends BaseMvpActivity {

    GridView likelist;
    List<ProductBean> list = new ArrayList<>();
    LikeGoodAdapter mLikeGoodAdapter;
    TitleBarView titlebar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_popular);
    }

    @Override
    public void initViews() {
        likelist = (GridView) findViewById(R.id.likelist);
        titlebar = (TitleBarView) findViewById(R.id.titlebar);
        if(getIntent().hasExtra("list")){
            list = (List<ProductBean>) getIntent().getSerializableExtra("list");

        }else {
            getHomePageIndexData();
        }
    }

    @Override
    public void initEvents() {
        titlebar.setOnTitleBarClickListener(new TitleBarView.TitleBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });
        mLikeGoodAdapter = new LikeGoodAdapter(getContext(), list);
        likelist.setAdapter(mLikeGoodAdapter);
    }


    private void getHomePageIndexData() {
        ApiDataRepository.getInstance().getIndex(null, new ApiNetResponse<HomePageIndex>() {
            @Override
            public void onSuccess(HomePageIndex data) {

                list.addAll(data.getRenqi());
                mLikeGoodAdapter.pushData(list);
            }
        });
    }

}
